gtkplacessidebar: improve heuristics for external drives
authorCarlos Soriano <csoriano@gnome.org>
Wed, 14 Oct 2015 19:42:16 +0000 (21:42 +0200)
committerCarlos Soriano <csoriano@gnome.org>
Thu, 15 Oct 2015 17:16:56 +0000 (19:16 +0200)
Since the change to use GtkPlacesView we don't want to show
internal storage on the sidebar.

In our case we were checking for drive_can_eject and
drive_is_media_removable.

However for some external hard drives it's reported that they
are not ejectable nor the have removable media. So the only
attribute that they have different from internal drives is that
they can be stopped.
So check for if the drive can be stopped to decide if it is
external or internal.

On the way realized we don't need to check for the mounts associated
with the volume to know if the volume can be ejected or not. So remove
that code.

https://bugzilla.gnome.org/show_bug.cgi?id=756589

gtk/gtkplacessidebar.c

index d8a21908adcd843e2a667831112688a5b8940b23..42179c333332a7dca534cd204a4b4dba81078c29 100644 (file)
@@ -823,36 +823,29 @@ out:
 }
 
 static gboolean
-is_removable_volume (GVolume *volume)
+is_external_volume (GVolume *volume)
 {
-  gboolean is_removable;
+  gboolean is_external;
   GDrive *drive;
-  GMount *mount;
   gchar *id;
 
   drive = g_volume_get_drive (volume);
-  mount = g_volume_get_mount (volume);
   id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS);
 
-  is_removable = g_volume_can_eject (volume);
+  is_external = g_volume_can_eject (volume);
 
   /* NULL volume identifier only happens on removable devices */
-  is_removable |= !id;
+  is_external |= !id;
 
   if (drive)
-    {
-      is_removable |= g_drive_can_eject (drive);
-      is_removable |= g_drive_is_media_removable (drive);
-    }
-
-  if (mount)
-    is_removable |= (g_mount_can_eject (mount) && !g_mount_can_unmount (mount));
+    is_external |= g_drive_can_eject (drive) ||
+                   g_drive_is_media_removable (drive) ||
+                   g_drive_can_stop (drive);
 
   g_clear_object (&drive);
-  g_clear_object (&mount);
   g_free (id);
 
-  return is_removable;
+  return is_external;
 }
 
 static void
@@ -991,7 +984,7 @@ update_places (GtkPlacesSidebar *sidebar)
                 }
               g_free (identifier);
 
-              if (sidebar->show_other_locations && !is_removable_volume (volume))
+              if (sidebar->show_other_locations && !is_external_volume (volume))
                 {
                   g_object_unref (volume);
                   continue;
@@ -1095,7 +1088,7 @@ update_places (GtkPlacesSidebar *sidebar)
         }
       g_free (identifier);
 
-      if (sidebar->show_other_locations && !is_removable_volume (volume))
+      if (sidebar->show_other_locations && !is_external_volume (volume))
         {
           g_object_unref (volume);
           continue;